//
// General settings and global helpers
// -----------------------------------------------------------------------------

QUnit.testDone = function (name, bad, total) {
	// Collapse failed tests
	$('#qunit-tests li.fail > ol:visible').hide();
};

// Setup/teardown procedures for testing JSReg
var JSRegTestEnv = {
	setup: function () {
		this.JSReg = JSReg.create();
		
		this.JSReg.setDebugObjects({
			errorHandler: function(e) {
				throw e;
			}
		});

		var self = this;
		this.runV8Test = jQuery.proxy(function (jsFile) {
			this.JSReg.extendWindow('$assertEquals$', function (expected, actual, title) {
				equal(actual, expected, title);
			});
			this.JSReg.extendWindow('$assertTrue$', function (value, title) {
				ok(value, title);
			});
			this.JSReg.extendWindow('$assertFalse$', function (value, title) {				
				ok(!value, title);
			});
			this.JSReg.extendWindow('$assertThrows$', function (code, title) {
				raises(function () {					
					self.JSReg.eval(code);
				}, title);
			});
			
			var xhr = jQuery.ajax({
				url: jsFile,
				async: false,
				dataType: "text"
			});

			this.JSReg.eval(xhr.responseText);			
		}, this);
	},
	teardown: function () {
		this.JSReg.destroy();
	}
};

function v8test(name, ex) {
	var module = QUnit.config.currentModule;
	test(name, function () {
		expect(ex);
		this.runV8Test(module+'/'+name+'.js');
	});
};

// -----------------------------------------------------------------------------